import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import tabbars from "./tabbars";
import LayoutBack from "@/layouts/back/index.vue";
const routes: Array<RouteRecordRaw> = [
  ...tabbars.routers,
  {
    path: "/login",
    name: "登陆",
    component: LayoutBack,
    children: [
      {
        path: "",
        component: () => import("@/views/login/index.vue"),
        meta: {
          title: "登陆",
          offHeader: true,
        },
      },
    ],
  },
  {
    path: "/register",
    name: "注册",
    component: LayoutBack,
    children: [
      {
        path: "",
        component: () => import("@/views/login/register.vue"),
        meta: {
          title: "注册",
          offHeader: true,
        },
      },
    ],
  },
  {
    path: "/userinfo",
    name: "用户",
    component: LayoutBack,
    children: [
      {
        path: "settings",
        component: () => import("@/views/user/settings.vue"),
        meta: {
          title: "个人资料",
        },
      },
    ],
  },
  {
    path: "/orderMeal",
    name: "订单和餐品",
    component: LayoutBack,
    children: [
      {
        path: "submit",
        name: "提交订单",
        component: () => import("@/views/orderMeal/submit.vue"),
        meta: {
          title: "提交订单",
        },
      },
      {
        path: "remark",
        name: "编辑备注",
        component: () => import("@/views/orderMeal/remark.vue"),
        meta: {
          title: "编辑备注",
        },
      },
    ],
  },
  {
    path: "/address",
    name: "地址",
    component: LayoutBack,
    children: [
      {
        path: "list",
        name: "地址列表",
        component: () => import("@/views/address/list.vue"),
        meta: {
          title: "地址列表",
        },
      },
      {
        path: "edit",
        name: "地址管理",
        component: () => import("@/views/address/edit.vue"),
        meta: {
          title: "地址管理",
        },
      },
    ],
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

router.beforeEach((to, from, next) => {
  const orderMealToken = window.localStorage.getItem("orderMealToken");
  //改变vuex的值

  next();
});

export default router;
